package logic

import (
	"context"
	"math/rand"
	"time"
	"zkzk2/models/redis"
	"zkzk2/zk2rpc/internal/svc"
	"zkzk2/zk2rpc/zk2rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *zk2rpc.SendSmsRequest) (*zk2rpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line

	Intn := rand.Intn(90000) + 10000
	//sms, err := pkg.SendSms(in.Tel, strconv.Itoa(Intn))
	//if err != nil {
	//	return nil, err
	//}
	//if *sms.Body.Code != "OK" {
	//	return nil, fmt.Errorf(*sms.Body.Message)
	//}
	redis.Client.Set("sendsms"+in.Tel+in.Source, Intn, time.Minute*10)
	return &zk2rpc.SendSmsResponse{}, nil
}
